
var animation; // 动画实体
var ani_index = 0; // 动画执行次数index（当前执行了多少次）
var aniIntervalId = -1;
var tuiwa = require("../../tuiwa.js");

Page({
  data: {
    setInter: '',
    widthProgress: 0,
    testLoadingLayer: true,
    resultShowFlag: false,
    lead: false,
    height: 28,
    width: 37,
    gg: false,
    rightImg: "",
    leftImg: "",
    topImg: "",
    resultImg: "",
    hourseId: 0,
    duiLianId: 0,
    screenHeight: 0,
    screenWidth: 0,
    //对联位置
    moveType: "",
    canMove: "",
    right_left: -10,
    right_bottom: 30,
    left_left: 100,
    left_bottom: 30,
    top_left: 33.5,
    top_bottom: 100,
    hourseImgList: [
      {
        houseImg: "https://fcdn.qiushilaile.com/adx/adx-92441611051741285.png",
        id: 0,
      }, {
        houseImg: "https://fcdn.qiushilaile.com/adx/adx-39891611117022796.png",
        id: 1,
      }, {
        houseImg: "https://fcdn.qiushilaile.com/adx/adx-77501611123675747.png",
        id: 2,
      }],
    resultImgList: {
      result_0_0: "https://fcdn.qiushilaile.com/adx/adx-45551611197067083.png",
      result_0_1: "https://fcdn.qiushilaile.com/adx/adx-12981611197078428.png",
      result_0_2: "https://fcdn.qiushilaile.com/adx/adx-74421611197072924.png",
      result_0_3: "https://fcdn.qiushilaile.com/adx/adx-20551611197062415.png",
      result_1_0: "https://fcdn.qiushilaile.com/adx/adx-73501611197034011.png",
      result_1_1: "https://fcdn.qiushilaile.com/adx/adx-72521611197022893.png",
      result_1_2: "https://fcdn.qiushilaile.com/adx/adx-61481611197028113.png",
      result_1_3: "https://fcdn.qiushilaile.com/adx/adx-71861611197038953.png",
      result_2_0: "https://fcdn.qiushilaile.com/adx/adx-37491611196984118.png",
      result_2_1: "https://fcdn.qiushilaile.com/adx/adx-63211611196967644.png",
      result_2_2: "https://fcdn.qiushilaile.com/adx/adx-90631611196975428.png",
      result_2_3: "https://fcdn.qiushilaile.com/adx/adx-56891611196991223.png",
    },
    duiLianList: [
      {
        rightImg: "https://fcdn.qiushilaile.com/adx/adx-44501611051745624.png",
        leftImg: "https://fcdn.qiushilaile.com/adx/adx-56211611051749221.png",
        topImg: "https://fcdn.qiushilaile.com/adx/adx-77611611051752309.png",
        id: 0,
      }, {
        rightImg: "https://fcdn.qiushilaile.com/adx/adx-10671611116713826.png",
        leftImg: "https://fcdn.qiushilaile.com/adx/adx-52351611116718867.png",
        topImg: "https://fcdn.qiushilaile.com/adx/adx-29071611116764914.png",
        id: 0,
      }, {
        rightImg: "https://fcdn.qiushilaile.com/adx/adx-33261611116906580.png",
        leftImg: "https://fcdn.qiushilaile.com/adx/adx-77791611116911606.png",
        topImg: "https://fcdn.qiushilaile.com/adx/adx-74951611116956532.png",
        id: 0,
      }, {
        rightImg: "https://fcdn.qiushilaile.com/adx/adx-52791611129703783.png",
        leftImg: "https://fcdn.qiushilaile.com/adx/adx-88331611129709465.png",
        topImg: "https://fcdn.qiushilaile.com/adx/adx-37471611129714430.png",
        id: 0,
      }
    ],
    hasUseList: [],
    canvas: "",
    click_step: 0,
    click_right: {},
    click_left: {},
    click_top: {},
    click_right_list: [
      {
        left: 70,
        top: 43,
        show: false,
      }, {
        left: 75,
        top: 43,
        show: false,
      }, {
        left: 77,
        top: 40,
        show: false,
      }
    ],
    click_left_list: [
      {
        left: 19,
        top: 43,
        show: false,
      }, {
        left: 8,
        top: 43,
        show: false,
      }, {
        left: 14,
        top: 40,
        show: false,
      }
    ],
    click_top_list: [
      {
        left: 32,
        top: 28,
        show: false,
      }, {
        left: 33,
        top: 38,
        show: false,
      }, {
        left: 33,
        top: 28,
        show: false,
      }
    ],

    ani_right: '',
    ani_left: '',
    ani_top: '',
  },
  onLoad: function (options) {
    var that = this;
    tt.setStorageSync('g_id', 'duilian');
    tuiwa.globalData.currentPage = this;
    this.setData({
      hourseImage: this.data.hourseImgList[0].houseImg,
      hourseId: 0,
    })
    that.setData({
      rightImg: that.data.duiLianList[0].rightImg,
      leftImg: that.data.duiLianList[0].leftImg,
      topImg: that.data.duiLianList[0].topImg,
      resultImg: that.data.resultImgList.result_0_0,
    })
    that.setData({
      canvas: 1
    })
    var systemInfo = wx.getSystemInfoSync();
    that.setData({
      screenWidth: systemInfo.windowWidth,
      screenHeight: systemInfo.windowHeight
    })
    console.log(this.data.screenHeight, this.data.screenWidth)
    this.setData({
      click_right: {
        left: that.data.click_right_list[that.data.hourseId].left,
        top: that.data.click_right_list[that.data.hourseId].top,
        show: true,
      },
      canMove: "right",
    })
    setTimeout(() => {
      this.startSetInter()
    }, 3000)
    that.canvas()

    setTimeout(() => {
      this.setData({
        lead: false
      })
    }, 7000)
    let openId = tt.getStorageSync('openId')
    let dlId = tt.getStorageSync('dlId')
    if (dlId) {
      console.log('dlId存在', dlId)
    } else {
      console.log('dlId不存在')
      this.setData({
        lead: true
      })
      tt.setStorageSync('dlId', openId);
    }
  },
  currentClick() {
    if (this.data.currentDuiLianId == "right") {
      this.rightToLeft()
    }
    if (this.data.currentDuiLianId == "left") {
      this.leftToLeft()
    }
    if (this.data.currentDuiLianId == "top") {
      this.topToBottom()
    }
  },
  rightToLeft() {
    var that = this;
    this.endSetInter()
    console.log(this.data.hourseId)
    if (that.data.hourseId == 0) {
      console.log('背景1')
      if (that.data.right_left < 69.8) {
        tt.showToast({ title: "按得太早了哦！" });
        setTimeout(res => {
          that.setData({
            gg: true,
            kong: true
          })
        }, 1000)
      }
      if (that.data.right_left > 69.8 && that.data.right_left < 74.8) {
        tt.showToast({ title: "完美！" });
        console.log("111")
        that.data.setInter = setInterval(() => {
          that.setData({
            left_left: that.data.left_left - 0.5,
            currentDuiLianId: "left",
          })
          if (that.data.left_left > 12.8 && that.data.left_left < 16.8) {
            that.endSetInter()
            tt.showToast({ title: "手速不够哦！" });
            setTimeout(res => {
              that.setData({
                gg: true,
                kong: true
              })
            }, 1000)
          }
        }, 20)
        console.log('111111')
        this.data.click_left = this.data.click_left_list[this.data.hourseId];
        this.data.click_right.show = false;
        this.data.click_left.show = true;
        // if (this.data.right_left > this.data.click_right.left
        //   && this.data.right_bottom > 100 - this.data.click_right.top - 28
        // ) {
        this.setData({
          click_left: this.data.click_left,
          click_right: this.data.click_right,
          canMove: 'left'
        })
        // }
      }
    }
    if (that.data.hourseId == 1) {
      console.log('背景2')
      if (that.data.right_left < 74.8) {
        tt.showToast({ title: "按得太早了哦！" });
        setTimeout(res => {
          that.setData({
            gg: true,
            kong: true
          })
        }, 1000)
      }
      if (that.data.right_left > 74.8 && that.data.right_left < 79.3) {
        tt.showToast({ title: "完美！" });
        that.data.setInter = setInterval(() => {
          that.setData({
            left_left: that.data.left_left - 0.5,
            currentDuiLianId: "left",
          })
          if (that.data.left_left < 7.8) {
            that.endSetInter()
            tt.showToast({ title: "手速不够哦！" });
            setTimeout(res => {
              that.setData({
                gg: true,
                kong: true
              })
            }, 1000)
          }
        }, 20)
        console.log('111111_1111')
        this.data.click_left = this.data.click_left_list[this.data.hourseId];
        this.data.click_right.show = false;
        this.data.click_left.show = true;
        // if (this.data.right_left > this.data.click_right.left
        //   && this.data.right_bottom > 100 - this.data.click_right.top - 28
        // ) {
        this.setData({
          click_left: this.data.click_left,
          click_right: this.data.click_right,
          canMove: 'left'
        })
        // }
      }
    }
    if (that.data.hourseId == 2) {
      console.log('背景3')
      if (that.data.right_left < 76.8) {
        tt.showToast({ title: "按得太早了哦！" });
        setTimeout(res => {
          that.setData({
            gg: true,
            kong: true
          })
        }, 1000)
      }
      if (that.data.right_left > 76.8 && that.data.right_left < 81.3) {
        tt.showToast({ title: "完美！" });
        that.data.setInter = setInterval(() => {
          that.setData({
            left_left: that.data.left_left - 0.5,
            currentDuiLianId: "left",
          })
          if (that.data.left_left < 13.8) {
            that.endSetInter()
            tt.showToast({ title: "手速不够哦！" });
            setTimeout(res => {
              that.setData({
                gg: true,
                kong: true
              })
            }, 1000)
          }
        }, 20)
        console.log('111111_1111')
        this.data.click_left = this.data.click_left_list[this.data.hourseId];
        this.data.click_right.show = false;
        this.data.click_left.show = true;
        // if (this.data.right_left > this.data.click_right.left
        //   && this.data.right_bottom > 100 - this.data.click_right.top - 28
        // ) {
        this.setData({
          click_left: this.data.click_left,
          click_right: this.data.click_right,
          canMove: 'left'
        })
        // }
      }
    }
  },
  leftToLeft() {
    var that = this;
    this.endSetInter()
    if (that.data.hourseId == 0) {
      console.log('背景1')
      if (that.data.left_left > 22.8) {
        tt.showToast({ title: "按得太早了哦！" });
        setTimeout(res => {
          that.setData({
            gg: true,
            kong: true
          })
        }, 1000)
      }
      if (that.data.left_left >= 17.6 && that.data.left_left < 22.8) {
        tt.showToast({ title: "完美！" });
        console.log("222")
        this.data.click_top = this.data.click_top_list[this.data.hourseId]
        this.data.click_left.show = false;
        this.data.click_top.show = true;
        this.setData({
          click_left: this.data.click_left
        })
        this.setData({
          click_top: this.data.click_top,
          canMove: "top"
        })
        that.data.setInter = setInterval(() => {
          that.setData({
            top_bottom: that.data.top_bottom - 0.2,
            currentDuiLianId: "top",
          })
          if (that.data.top_bottom > 63.9 && that.data.top_bottom < 64.9) {
            that.endSetInter()
            tt.showToast({ title: "手速不够哦！" });
            setTimeout(res => {
              that.setData({
                gg: true,
                kong: true
              })
            }, 1000)
          }
        }, 20)
      }
      if (that.data.left_left < 17.6) {
        tt.showToast({ title: "手速不够哦！" });
        setTimeout(res => {
          that.setData({
            gg: true,
            kong: true
          })
        }, 1000)
      }
    }
    if (that.data.hourseId == 1) {
      console.log('背景2')
      console.log(that.data.left_left)
      if (that.data.left_left > 12.8) {
        tt.showToast({ title: "按得太早了哦！" });
        setTimeout(res => {
          that.setData({
            gg: true,
            kong: true
          })
        }, 1000)
      }
      if (that.data.left_left >= 7.8 && that.data.left_left < 12.8) {
        tt.showToast({ title: "完美！" });
        this.data.click_top = this.data.click_top_list[this.data.hourseId]
        this.data.click_left.show = false;
        this.data.click_top.show = true;
        this.setData({
          click_left: this.data.click_left
        })
        this.setData({
          click_top: this.data.click_top,
          canMove: "top"
        })
        that.data.setInter = setInterval(() => {
          that.setData({
            top_bottom: that.data.top_bottom - 0.2,
            currentDuiLianId: "top",
          })
          if (that.data.top_bottom < 54.8) {
            that.endSetInter()
            console.log(that.data.top_bottom)
            tt.showToast({ title: "手速不够哦！" });
            setTimeout(res => {
              that.setData({
                gg: true,
                kong: true
              })
            }, 1000)
          }
        }, 20)
      }
    }
    if (that.data.hourseId == 2) {
      console.log('背景3')
      if (that.data.left_left > 18.8) {
        tt.showToast({ title: "按得太早了哦！" });
        setTimeout(res => {
          that.setData({
            gg: true,
            kong: true
          })
        }, 1000)
      }
      if (that.data.left_left >= 13.8 && that.data.left_left < 18.8) {
        tt.showToast({ title: "完美！" });
        this.data.click_top = this.data.click_top_list[this.data.hourseId]
        this.data.click_left.show = false;
        this.data.click_top.show = true;
        this.setData({
          click_left: this.data.click_left
        })
        this.setData({
          click_top: this.data.click_top,
          canMove: "top"
        })
        that.data.setInter = setInterval(() => {
          that.setData({
            top_bottom: that.data.top_bottom - 0.2,
            currentDuiLianId: "top",
          })
          if (that.data.top_bottom < 65.3) {
            that.endSetInter()
            console.log(that.data.top_bottom)
            tt.showToast({ title: "手速不够哦！" });
            setTimeout(res => {
              that.setData({
                gg: true,
                kong: true
              })
            }, 1000)
          }
        }, 20)
      }
    }
  },
  topToBottom() {
    var that = this;
    this.endSetInter()
    if (that.data.hourseId == 0) {
      console.log('背景1')
      if (that.data.top_bottom > 66.8) {
        tt.showToast({ title: "按得太早了哦！" });
        setTimeout(res => {
          that.setData({
            gg: true,
            kong: true
          })
        }, 1000)
      }
      if (that.data.top_bottom < 66.8 && that.data.top_bottom > 65.1) {
        tt.showToast({ title: "完美！" });
        // this.aniTopStart()
        console.log("333")
        this.data.click_top.show = false;
        this.setData({
          click_top: this.data.click_top,
          canMove: ""
        })
        var that = this;
        setTimeout(res => {
          that.setData({
            resultShowFlag: true,
            kong: true
          })
        }, 1000)
      }
      if (that.data.top_bottom < 65.1) {
        tt.showToast({ title: "手速不够哦！" });
        setTimeout(res => {
          that.setData({
            gg: true,
            kong: true
          })
        }, 1000)
      }
    }
    if (that.data.hourseId == 1) {
      console.log('背景2', this.data.top_left)
      if (that.data.top_bottom > 56.8) {
        tt.showToast({ title: "按得太早了哦！" });
        setTimeout(res => {
          that.setData({
            gg: true,
            kong: true
          })
        }, 1000)
      }
      if (that.data.top_bottom < 56.8 && that.data.top_bottom > 54.8) {
        tt.showToast({ title: "完美！" });
        // this.aniTopStart()
        console.log(this, "333")
        this.data.click_top.show = false;
        this.setData({
          click_top: this.data.click_top,
          canMove: ""
        })
        var that = this;
        setTimeout(res => {
          that.setData({
            resultShowFlag: true,
            kong: true
          })
        }, 1000)
      }
    }
    if (that.data.hourseId == 2) {
      console.log('背景3')
      if (that.data.top_bottom > 66.8) {
        tt.showToast({ title: "按得太早了哦！" });
        setTimeout(res => {
          that.setData({
            gg: true,
            kong: true
          })
        }, 1000)
      }
      if (that.data.top_bottom < 66.8 && that.data.top_bottom > 65.1) {
        tt.showToast({ title: "完美！" });
        // this.aniTopStart()
        console.log(this, "333")
        this.data.click_top.show = false;
        this.setData({
          click_top: this.data.click_top,
          canMove: ""
        })
        var that = this;
        setTimeout(res => {
          that.setData({
            resultShowFlag: true,
            kong: true
          })
        }, 1000)
      }
    }
  },
  startSetInter: function () {
    var that = this;
    //将计时器赋值给setInter
    if (that.data.hourseId == 0) {
      console.log('背景1', that.data.click_right.top + that.data.height)
      that.data.setInter = setInterval(() => {
        that.setData({
          right_left: that.data.right_left + 0.5,
          currentDuiLianId: "right",
        })
        if (that.data.right_left > 74.8 && that.data.right_left < 75.8) {
          console.log(that.data.right_left)
          that.endSetInter()
          tt.showToast({ title: "手速不够哦！" });
          setTimeout(res => {
            that.setData({
              gg: true,
              kong: true
            })
          }, 1000)
        }
      }, 20)
    }
    if (that.data.hourseId == 1) {
      console.log('背景2')
      that.data.setInter = setInterval(() => {
        that.setData({
          right_left: that.data.right_left + 0.5,
          currentDuiLianId: "right",
        })
        if (that.data.right_left > 79.3) {
          console.log(that.data.right_left)
          that.endSetInter()
          tt.showToast({ title: "手速不够哦！" });
          setTimeout(res => {
            that.setData({
              gg: true,
              kong: true
            })
          }, 1000)
        }
      }, 20)
    }
    if (that.data.hourseId == 2) {
      that.setData({
        right_bottom: 33,
        left_bottom: 33
      })
      console.log('背景3', that.data.right_bottom, that.data.left_bottom)
      that.data.setInter = setInterval(() => {
        that.setData({
          right_left: that.data.right_left + 0.5,
          currentDuiLianId: "right",
        })
        if (that.data.right_left > 81.3) {
          console.log(that.data.right_left)
          that.endSetInter()
          tt.showToast({ title: "手速不够哦！" });
          setTimeout(res => {
            that.setData({
              gg: true,
              kong: true
            })
          }, 1000)
        }
      }, 20)
    }
  },
  endSetInter: function () {
    var that = this;
    //清除计时器  即清除setInter
    clearInterval(that.data.setInter)
  },
  bindload() {
    this.setData({
      testLoadingLayer: false
    })
    console.log('图片加载完毕')
  },
  again() {
    tt.redirectTo({
      url: '../../pages/duilian/duilian' // 指定页面的url
    });
  },
  toIndex() {
    tt.reLaunch({
      url: '../../pages/index/index' // 指定页面的url
    });
  },
  back: function () {
    console.log('111')
    tt.navigateBack();
  },
  onReady() {
    ani_index = 0;
    aniIntervalId = -1;
    this.data.animation = '';
    animation = tt.createAnimation({
      duration: 800,
      timingFunction: 'linear', // "linear","ease","ease-in","ease-in-out","ease-out","step-start","step-end"
      delay: 0, // 0延迟
      transformOrigin: '50% 50% 0'
    })
    // this.setData({
    //   kong: false
    // })
    this.startAnimationInterval()
  },
  aniScale: function (n) { // 缩放动画
    if (n % 2 == 0) {
      animation.scale(1.15).step();
    } else {
      animation.scale(1.0).step();
    }
    this.setData({
      animation: animation.export()
    });
  },
  startAnimationInterval: function () { // 开始缩放
    var that = this;
    that.aniScale(++ani_index); // 进行一次缩放
    aniIntervalId = setInterval(function () {
      that.aniScale(++ani_index);
    }, 800); // 每间隔0.8s进行一次缩放
  },
  aniLeftStart: function () {
    let left = this.data.click_left.left;
    let top = this.data.click_left.top;
    left = (left / 100 - 0.2) * this.data.screenWidth;
    top = ((top + 25 + 2) / 100 - 1) * this.data.screenHeight;
    console.log(left, top)
    let animation = tt.createAnimation({
      duration: 1000,
      timingFunction: 'ease',
      delay: 100
    });
    animation.opacity(1).translate(left, top).step()
    this.setData({
      ani_left: animation.export()
    })
  },
  aniTopStart: function () {
    let left = this.data.click_top.left;
    let top = this.data.click_top.top;
    left = (left / 100 - 0.33) * this.data.screenWidth;
    top = ((top + 25 + 5) / 100 - 1) * this.data.screenHeight;
    console.log(left, top)
    let animation = tt.createAnimation({
      duration: 1000,
      timingFunction: 'ease',
      delay: 100
    });
    animation.opacity(1).translate(left, top).step()
    this.setData({
      ani_top: animation.export()
    })
  },
  aniRightStart: function () {
    let left = this.data.click_right.left;
    let top = this.data.click_right.top;
    left = (left / 100 - 0.7) * this.data.screenWidth;
    top = ((top + 25 + 2) / 100 - 1) * this.data.screenHeight;

    console.log(left, top)
    let animation = tt.createAnimation({
      duration: 1000,
      timingFunction: "cubic-bezier(0.2,2,0.6,2)",
      delay: 100
    });
    animation.opacity(1).translate(left, top).step()

    this.setData({
      ani_right: animation.export()
    })
  },
  canvas: async function () { // canvas展示倒计时
    var that = this;
    var step = 1,//计数动画次数
      num = -1,//计数倒计时秒数（n - num）
      start = 1.5 * Math.PI,// 开始的弧度
      end = -0.5 * Math.PI,// 结束的弧度
      time = null;// 计时器容器
    var animation_interval = 1000,// 每1秒运行一次计时器
      n = 2; // 当前倒计时为5秒
    // 动画函数
    function animation() {
      if (step <= n) {
        end = end + 2 * Math.PI / n;
        ringMove(start, end);
        step++;
      } else {
        that.setData({
          canvas: 0
        })
        clearInterval(time);
      }
    };
    // 画布绘画函数
    function ringMove(s, e) {
      var context = tt.createCanvasContext('secondCanvas')
      var gradient = context.createLinearGradient(200, 100, 100, 200);
      gradient.addColorStop("0", "#2661DD");
      gradient.addColorStop("0.5", "#40ED94");
      gradient.addColorStop("1.0", "#5956CC");
      // 绘制倒计时文本
      context.beginPath()
      context.setLineWidth(2)
      context.setFontSize(40)
      context.setFillStyle('#ffffff')
      context.setTextAlign('center')
      context.setTextBaseline('middle')
      context.fillText(n - num + '', 42, 42, 30)
      context.fill()
      context.closePath()
      context.draw()
      // 每完成一次全程绘制就+1
      num++;
    }
    // 倒计时前先绘制整圆的圆环
    ringMove(start, end);
    // 创建倒计时
    time = setInterval(animation, animation_interval);
    // console.log(this.data.canvas)
  },
  //按钮事件
  changeDuiLian: function () {
    this.startSetInter()
    let duiLianId = this.data.duiLianId + 1;
    if (duiLianId >= this.data.duiLianList.length) {
      duiLianId = 0;
    }
    let hourseId = this.data.hourseId;
    let resultKey = "result_" + hourseId + "_" + duiLianId;
    console.log(resultKey, "resultkey")
    let resultImg = this.data.resultImgList[resultKey]
    console.log(resultImg, "resulssssssssssss")
    this.setData({
      duiLianId: duiLianId,
      hourseId: hourseId,
      rightImg: this.data.duiLianList[duiLianId].rightImg,
      leftImg: this.data.duiLianList[duiLianId].leftImg,
      topImg: this.data.duiLianList[duiLianId].topImg,
      resultImg: resultImg,
      resultShowFlag: false,
      kong: false
    })
    this.resetDuiLian()
  },
  changeHourse: function () {
    console.log(this.data.top_left)
    setTimeout(() => {
      this.startSetInter()
    }, 3000)
    this.setData({
      testLoadingLayer: true,
    })
    setTimeout(() => {
      this.setData({
        testLoadingLayer: false
      })
    }, 4000)
    let duiLianId = this.data.duiLianId;
    let hourseId = this.data.hourseId + 1;
    if (hourseId >= this.data.hourseImgList.length) {
      hourseId = 0;
    }
    let resultKey = "result_" + hourseId + "_" + duiLianId;
    let resultImg = this.data.resultImgList[resultKey]
    console.log("duilianlist: " + this.data.duiLianList[duiLianId])
    this.setData({
      duiLianId: duiLianId,
      hourseId: hourseId,
      rightImg: this.data.duiLianList[duiLianId].rightImg,
      leftImg: this.data.duiLianList[duiLianId].leftImg,
      topImg: this.data.duiLianList[duiLianId].topImg,
      resultImg: resultImg,
      resultShowFlag: false,
      hourseImage: this.data.hourseImgList[hourseId].houseImg,
      kong: false
    })
    console.log(hourseId)
    this.resetDuiLian()
  },
  closeAdFunction: function (e) {
    var that = this;
    console.log(that.data.resultImg, "rrrrrrrrrrrrrr1111")
    tt.authorize({
      scope: "scope.album",
      success: (res) => {
        console.log(that.data.resultImg, "rrrrrrrrrrrrrr")
        tt.getImageInfo({
          src: that.data.resultImg,
          header: {
            "content-type": "application/json",
          },
          success: (res) => {
            console.log("res222   " + res)
            let filePath = res.path;
            console.log(filePath, "fffffffff")
            tt.saveImageToPhotosAlbum({
              filePath, // 暂不支持网络图片/本地图片地址，需与tt.downloadFile一起使用
              success: (res) => {
                tt.showToast({ title: "成功保存到本地相册" });
              },
              fail: (err) => {
                let errType = err.errMsg.includes("saveImageToPhotosAlbum:fail cancel")
                  ? "取消保存"
                  : "保存失败";
                tt.showModal({
                  title: errType,
                  content: err.errMsg,
                  showCancel: false,
                });
              },
            });
          },
          fail: (err) => {
            tt.showModal({
              title: "下载出错",
              content: err.errMsg,
              showCancel: false,
            });
          },
        });

      },
      fail: (err) => {
        console.log("authorize fail", err);
        tt.showModal({
          title: "授权出错",
          content: err.errMsg,
          showCancel: false,
        });
      },
    });
  },
  cancelAdFunction: function (e) {
    tt.showModal({
      title: "温馨提示",
      content: "要观看完整视频才能继续哦~",
      showCancel: !1
    })
  },
  saveResult: function (e) {
    tt.showModal({
      title: '温馨提示',
      content: '点击确定前往观看视频',
      cancelText: '取消',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定');
          tuiwa.playAd();
        } else if (res.cancel) {
          console.log('用户点击取消');
        }
      }
    });
  },
  resetDuiLian: function () {
    var that = this;
    that.setData({
      canvas: 1,
      right_left: -10,
      right_bottom: 30,
      left_left: 100,
      left_bottom: 30,
      top_left: 33.5,
      top_bottom: 100,
    })
    that.canvas()
    this.data.click_right = this.data.click_right_list[this.data.hourseId];
    this.data.click_right.show = true;
    // setTimeout(res => {
    this.setData({
      click_right: this.data.click_right,
      canMove: 'right',
      kong: false
    })
    // }, 4000)
  }
})